<?php
require_once ('../includes/SmartyManager.class.php');
require_once ('../includes/functions.inc.php');
require_once ('../includes/exceptions/AppExceptions.class.php');
require_once ('../includes/LogInserter.class.php');

$smarty = SmartyManager::getSmarty ();
try {
	if(!empty($_POST['certificationNumber'])){
		$mc = $_POST ['certificationNumber'];
		beginTransaction ();
		
		//先记录
		$query = "select * from little_ruku where certificationNumber = '$mc'";
		DB::query ( $query );
		$result = DB::getResult ();
		$rows = array ();
		while ( $row = $result->fetch_assoc () ) {
			array_push ( $rows, $row );
		}
		LogInserter::logForDelete ( $rows );
		$query = "select * from little_chuku where certificationNumber = '$mc'";
		DB::query ( $query );
		$result = DB::getResult ();
		$rows = array ();
		while ( $row = $result->fetch_assoc () ) {
			array_push ( $rows, $row );
		}
		LogInserter::logForDelete ( $rows );
		$query = "select * from little_main where certificationNumber = '$mc'";
		DB::query ( $query );
		$result = DB::getResult ();
		$rows = array ();
		while ( $row = $result->fetch_assoc () ) {
			array_push ( $rows, $row );
		}
		LogInserter::logForDelete ( $rows );
		
		deleteCertificationNumber ( $mc );
		commit ();
	}else{
		throw new Exception('产品质量证书号为空，不允许删除。');
	}
} catch ( Exception $e ) {
	rollback ();
	$smarty->assign ( 'errMsg', '删除时，操作数据库出现错误,错误原因：' . $e );
	$smarty->assign ( 'errTitle', '出现错误' );
	$smarty->display ( 'error.html' );
	die ();
}

$smarty->assign ( 'successMsg', '删除成功' );
$smarty->assign ( 'successTitle', '成功' );
$smarty->display ( 'success.html' );

?>